import re

TESTCASE_FILE = "../../../PRODUCT/python_tools/xts_check_demo/AAAATest.test.ets"

def get_function_content(file_path, pattern):
    function_content = []
    function_line = ""
    inside_function = False
    open_braces_count = 0
    in_comment = False
    in_string = False
    with open(file_path, 'r', encoding='utf-8') as file:
        for line in file:
            stripped_line = line.strip()
            if not inside_function:
                if re.search(pattern, line):
                    inside_function = True
                    open_braces_count = stripped_line.count('{')
                    function_line += line
            else:
                function_line += line
                i = 0
                while i < len(stripped_line):
                    char = stripped_line[i]
                    if in_comment:
                        if char == '*' and i < len(stripped_line) - 1 and stripped_line[i + 1] == '/':
                            in_comment = False
                            i += 1
                    elif in_string:
                        if char == in_string and (i == 0 or stripped_line[i - 1]!= '\\'):
                            in_string = False
                    elif char == '/' and i < len(stripped_line) - 1:
                        if stripped_line[i + 1] == '/':
                            break
                        elif stripped_line[i + 1] == '*':
                            in_comment = True
                            i += 1
                        elif char == '"' or char == "'":
                            in_string = char
                    elif char == '{':
                        open_braces_count += 1
                    elif char == '}':
                        open_braces_count -= 1
                        if open_braces_count == 0:
                            break
                    i += 1
                if open_braces_count == 0:
                    function_content.append(function_line)
                    function_line = ""
                    inside_function = False
    return function_content

if __name__ == '__main__':
    pattern = r"it\('.+'.+{"
    count = get_function_content(TESTCASE_FILE, pattern)
    print(count)


